﻿@using Webdiyer.WebControls.Mvc;
@model PagedList<Inspinia_MVC5.Models.Borrow>

    <table class="table table-striped">
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.Book.BookName)
            </th>
            <th>
                用户姓名
            </th>
            
            <th>
                @Html.DisplayNameFor(model => model.Role)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Status)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.JieYueDate)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.YingHuanDate)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.ReturnDate)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.OverDue)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.XuJieDate)
            </th>
            <th></th>
        </tr>

        @foreach (var item in Model)
        {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.Book.BookName)
                </td>
                <td>
                    @if (item.Role == 0)
                    {
                        @Html.DisplayFor(modelItem => item.Student.StuName)

                    }
                    else
                    {
                        @Html.DisplayFor(modelItem => item.Teacher.TeaName)

                    }

                </td>
                
                <td>
                    @(item.Role==0?"学生":"教师")
                </td>
                <td>
                    @{
                        if (item.Status == 1)
                        {
                            <span>已借阅</span>
                        }
                        else if (item.Status == 2)
                        {
                            <span>已续借</span>

                        }
                        else if (item.Status == 3)
                        {
                            <span>已还书</span>

                        }
                        else
                        {
                            <span>异常</span>

                        }
                    }
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.JieYueDate)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.YingHuanDate)
                    @{
                        DateTime dt1 = DateTime.Parse(item.YingHuanDate.ToString());
                        DateTime dt2 = DateTime.Now;
                        int result = (dt2 - dt1).Days;
                        bool result2 = result > 0;
                        bool result3 = result < 1 && result > -5;
                        if (result2)
                        {
                                        <span class="label label-danger">逾期</span>
                        }
                        if (result3)
                        {
                            <span class="label label-warning">临期</span>
                        }
                    }
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.ReturnDate)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.OverDue)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.XuJieDate)
                </td>
                <td>
                    @{
                        string status = ViewBag.Status;
                        if (status == null)
                        {
                            if (ViewBag.Admin)
                            {
                                @Html.ActionLink("详情", "Details", new { id = item.ID }, new { @class = "btn btn-primary btn-sm" })
                                @Html.ActionLink("编辑", "Edit", new { id = item.ID }, new { @class = "btn btn-white btn-sm" })
                                @Html.ActionLink("删除", "Delete", new { id = item.ID }, new { @class = "btn btn-white btn-sm" })

                            }

                        }
                        else if (status == "1")
                        {
                            @Html.ActionLink("续借", "Renew", new { id = item.ID }, new { @class = "btn btn-primary btn-sm" })

                        }
                        else if (status == "2")
                        {
                            @Html.ActionLink("还书", "Back", new { id = item.ID }, new { @class = "btn btn-white btn-sm" })

                        }
                    }


                </td>
            </tr>
        }

    </table>